<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改心理健康知识')" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>

</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-knowledge-edit" th:object="${mentalKnowledge}">
            <input name="mentalKnowledgeId" th:field="*{mentalKnowledgeId}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">心理健康知识标题：</label>
                <div class="col-sm-8">
                    <input name="mentalKnowledgeTitle" th:field="*{mentalKnowledgeTitle}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">心理健康知识内容：</label>
                <div class="col-sm-8">
                    <script id="editor" name="mentalKnowledgeContent" type="text/plain" style="height: 300px;"></script>
                    <textarea id="mentalKnowledgeContent" style="display: none;">[[*{mentalKnowledgeContent}]]</textarea>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">作者：</label>
                <div class="col-sm-8">
                    <input name="mentalKnowledgeAuthor" th:field="*{mentalKnowledgeAuthor}" class="form-control" type="text" >
                </div>
            </div>
            <div class="form-group" hidden>
                <label class="col-sm-3 control-label" >发布者：</label>
                <div class="col-sm-8">
                    <input name="loginName" th:field="*{loginName}" class="form-control" type="text" readonly>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">封面：</label>
                <div class="col-sm-8">
                    <input type="hidden" name="mentalKnowledgeFile" th:field="*{mentalKnowledgeFile}">
                    <div class="file-loading">
                        <input class="form-control file-upload" id="mentalKnowledgeFile" name="file" type="file">
                    </div>
                </div>
            </div>
            <div class="form-group"  >
                <label class="col-sm-3 control-label"> </label>
                <div class="col-sm-8">
                    <div   >
                       <h2 style="color: #5bc0de">每次编辑提交后都要重新审核!</h2>
                    </div>
                </div>
            </div>
            <div class="form-group" hidden="hidden">
                <label class="col-sm-3 control-label">审核状态：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('sys_posts_status')}">
                        <input name="status" th:value="2" class="form-control" type="text">
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-fileinput-js"/>
    <th:block th:include="include :: ueditor-js" />
    <script th:inline="javascript">
        var prefix = ctx + "system/knowledge";


        $(function () {
            var text = $("#mentalKnowledgeContent").text();
            var ue = UE.getEditor('editor');
            ue.ready(function () {
                ue.setContent(text);
            });
        })

        function getContentTxt() {
            return UE.getEditor('editor').getContentTxt();
        }




        $("#form-knowledge-edit").validate({
            focusCleanup: true,
            rules: {
                mentalKnowledgeTitle: {
                    remote: {
                        url: prefix + "/checkMentalKnowledgeTitleUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                            "mentalKnowledgeTitle": function () {
                                return $.common.trim($("#mentalKnowledgeTitle").val());
                            }
                        },
                        dataFilter: function (data, type) {
                            return $.validate.unique(data);
                        }
                    }
                }
            },
            messages: {
                "mentalKnowledgeTitle": {
                    remote: "该标题已存在"
                }
            },
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-knowledge-edit').serialize());
            }
        }

        $(".file-upload").each(function (i) {
            var val = $("input[name='" + this.id + "']").val()
            $(this).fileinput({
                'uploadUrl': ctx + 'common/upload',
                initialPreviewAsData: true,
                initialPreview: [val],
                maxFileCount: 1,
                autoReplace: true
            }).on('fileuploaded', function (event, data, previewId, index) {
                $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
            }).on('fileremoved', function (event, id, index) {
                $("input[name='" + event.currentTarget.id + "']").val('')
            })
            $(this).fileinput('_initFileActions');
        });


    </script>
</body>
</html>